/**
 * @author DingZhenYun
 * @create 2021-04-27 上午 8:48
 * @program: JavaSEDemo->CustomerList
 * @description:
 */
public class CustomerList {
    Customer[] customers;//用来保存客户对象的数组
    int total=0;//记录已保存客户对象的数量

    public CustomerList(int totalCustomer) {
        customers = new Customer[totalCustomer];
    }

    public Customer[] getCustomers() {
        return customers;
    }

    public void setCustomers(Customer[] customers) {
        this.customers = customers;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public boolean addCustomer(Customer customer) {
        if (total>=customers.length){
            return false;
        }else{
            customers[total++]=customer;
            return true;
        }

    }

    public boolean replaceCustomer(int index, Customer cust) {
        if(index>=total||index<0){
            return false;
        }else{
            customers[index]=cust;
            return true;
        }
    }

    public boolean deleteCustomer(int index) {
        if(index>=total||index<0){
            return false;
        }
        for(int i=index;i<total-1;i++){
            customers[i]=customers[i+1];
        }
        customers[--total]=null;
        return true;
    }

    public Customer[] getAllCustomers() {
        Customer[] custs = new Customer[total];
        for (int i = 0; i < total; i++) {
            custs[i] = customers[i];
        }
        return custs;
    }



    public Customer getCustomer(int index) {
        if (index < 0 || index >= total) return null;
        return customers[index];
    }
}
